<?php
/**
 * Created by PhpStorm.
 * User: vanity
 * Date: 2018/1/5
 * Time: 9:36
 */
namespace Admin\Model;
use Think\Model\RelationModel;
class RoleModel extends RelationModel
{
    protected $tableName = 'roles';
    protected $patchValidate = true;
    protected $_validate = array(
        array('name','require','用户名不能为空',0),
        array('name','require','用户名已存在！',1,'unique',1),
    );
    protected $_auto = array (
        array('created_time','time',1,'function'),
        array('updated_time','time',2,'function'),
    );
    protected $_link = array(
        'role_user'=>array(
            'mapping_type'=> self::HAS_MANY,
            'foreign_key'=>'role_id',
            'mapping_fields'=>'user_id',
        ),
        'permission_role'=>array( //权限和权限角色关联表
            'mapping_type'=> self::HAS_MANY,
            'foreign_key'=>'role_id',
            'mapping_fields'=>'permission_id',
        ),
    );
}